package com.cheng.example.atguigu.practice.proVscon.v3;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;


//阻塞队列
public class Test {

    BlockingQueue blockingQueue = new LinkedBlockingQueue(10);

    public void pro(Integer i) {
        try {
            blockingQueue.put(i);
            System.out.println("put: "+i);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void con(Integer i) {
        try {
            Object o = blockingQueue.take();
            System.out.println("take: "+o);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) {
        Test test = new Test();

        new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                test.con(i);
            }
        }).start();

        new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                test.pro(i);
            }
        }).start();
    }


}
